package jdbc;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class my {
    public static void main(String[] args) {


        Properties info = new Properties();
        try {
            InputStream input = my.class.getClassLoader()
                    .getResourceAsStream("config.properties");
            info.load(input);
        } catch (
                IOException e) {
// 退出
            return;
        }

        String url = "jdbc:mysql://localhost:3306/MyDB";
        try (
                Connection conn = DriverManager.getConnection(url, info)) {
            System.out.println("数据库连接成功：" + conn);
        } catch (
                SQLException e) {
            e.printStackTrace();
        }
    }
}


